<?php
/**
 * Contus Support
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@Contus Supportcommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Contus Support to newer
 * versions in the future. If you wish to customize Contus Support for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_blank
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
?>

<?php
//Get the value of productid and 'recent' recent deals parameter

$id = Mage::app()->getRequest()->getParam('id');
$cid = Mage::app()->getRequest()->getParam('cid');
$recent = Mage::app()->getRequest()->getParam('recent');


$zoom_level = Mage::getStoreConfig('catalog/gmap/zoom_level');
if (empty($zoom_level)) $zoom_level='14';

$timezone = explode(" ", $this->formatDate(null, 'long',true));
$startdate = $this->formatDate(null, 'short',true)." ".$timezone[count($timezone)-1];
$productId=Mage::getSingleton('core/session')->getProductID();

//sets product Id if it comes from recent deal page
if(isset($recent)){
   $productId=$id;
}
// load the products
if($productId == ''):?>
<div class="nodealtext clearfix ">  <?php echo "<h1>".$this->__('No Deal Available')."</h1>" ?></div>
<?php else: ?>
<div class="leftcontent">
        <?php
        $inif = '0';
        $model = Mage::getModel('catalog/product'); //getting product model
        $_product = $model->load($productId);
        $inif = '1';
	  $currencySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
		$currencySymbol = '' ;    
		       
         $dealstatus= $_product->getDealStatus();
         $discussionId=$_product->getIdentifier();
         $fbApiKey = Mage::getSingleton('facebook/config')->getApiKey();
        ?>

    <div class="topcontent clearfix"><h1><?php if (isset($cid)){echo $this->__("Today's Side Deal:");} else {echo $this->__("Today's Deal:");} ?> <span><?php echo $this->htmlEscape($_product->getName()) ?></span></h1></div>

    <fieldset class="no-display">
        <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
        <input type="hidden" name="related_product" id="related-products-field" value="" />
    </fieldset>

    <div class="left_column">
        <div class="buynowbox">
            <div class="leftbox_middle">
                <div class="buynow_value " ><?php $sp_price = floor($_product->getSpecialPrice()); ?>
                    <?php if($recent == 1){ ?>
                    <span class="price_value" ><?php echo $this->__('Closed'); ?></span>
                    <?php } else{?>
                    <span class="price_value"><?php echo $currencySymbol.Mage::helper('core')->currency($sp_price,true,true) ?>  </span>
                    <a href='<?php echo $this->getAddToCartUrl($_product) ?>' id="scriptbuynow" class="buynowbtn">Buy Now</a>
                    <?php }?><div class="clear"></div>
                </div>

                    <?php
                    $currentUrl = $this->helper('core/url')->getCurrentUrl();
                    $content = '&amp;';
                    //$map =   $_product->getsitemap();
                    $customersite = $_product->getcustomersite();
                    $highlight = $_product->gethightlight();
                    $fineprint =  $_product->getFineprint();
                    $website=$_product->getCustomerWebsite();
                    $phone=$_product->getQuestions();
                    $_description = $_product->getdescription();
                    if (!$_product->isGrouped()) {
                        $discount_price =  $_product->getPrice()-$_product->getSpecialPrice();
                        $discount = ($discount_price*100)/ $_product->getPrice();
                        $discount = round($discount); ?>
                <div class="dicount-boxes clearfix" >
                    <div class="clsdiscount_prices">
                        <h3><?php echo $this->__('Value'); ?></h3>
                        <span><?php echo  $currencySymbol.Mage::helper('core')->currency($_product->getPrice(),true,true) ?></span>
                    </div>
                    <div class="clsdiscount_prices middle" >
                        <h3><?php echo $this->__('Discount'); ?></h3>
                        <span><?php echo $discount.'%'; ?></span>
                    </div>
                    <div class="clsdiscount_prices" >
                        <h3><?php echo $this->__('Save'); ?></h3>
                        <span><?php echo  $currencySymbol.Mage::helper('core')->currency($discount_price,true,true); ?></span></div>
                    <div class="clear"></div>
                    <?php if($recent != 1){ ?>
                    <div class="gift_box clearfix" id ="script_gift_box">
                        <img src="<?php echo $this->getSkinUrl('images/gift.png') ?>" width="34" height="31" alt="gift" title="gift" class="clsgiftimg"/>
                        <div class="buy_friend"> <form name="gift" method="post" action="<?php echo $this->getAddToCartUrl($_product); ?>">
                                <input type="hidden" name="giftoption" value="gift" />
                                 <?php Mage::getSingleton('core/session')->setBuyProductId($_product->getId());?>
                                <a onclick="javascript:document.gift.submit()" class="clsbuyfriend" ><?php echo $this->__('Buy it for a friend!'); ?>
                                </a> </form>
                        </div>
                    </div>
                    <?php } ?>
                            <?php } ?>
                </div>
            </div>
            

            <!-- Deal Bought-->
            <div class="clsspace"></div>
                <?php

                if (!$_product->isGrouped()) {
                    $resultQuantity = $this->getQuantityPurchase($_product);
                }
                ?>
            <div class="dealstatus"> <div class="totalcount"><?php echo $resultQuantity[0]; ?> <?php echo $this->__('bought'); ?></div>
                <div class="deal_status" id ="deal_status">
                    <img src="<?php echo $this->getSkinUrl('images/'.$resultQuantity[1].'.png') ?>"  width="180" height="16" alt="Rate" title="Rate"  class="statusimg"/>
                    <div class="clsstatus"><?php echo $this->__($resultQuantity[2]);  ?></div>
                </div>
            </div>
            
            <!-- Deal Bought-->
                <?php
                //Adding the products cartUrl,specialprice,identifier to the session
                Mage::getSingleton('core/session')->setSpecialPrice($_product->getSpecialPrice());
                Mage::getSingleton('core/session')->setAddtocart($this->getAddToCartUrl($_product));
                //End of Adding the products cartUrl,specialprice,identifier to the session
                ?>
             <!--Time box-->
                <?php  //product's regular Price
                $todayDate =  Mage::getModel('catalog/product')->getResource()->formatDate($_product->getspecial_to_date(),false);
                $expirydate = $todayDate.' '.$_product->gettime();
                ?>
            <script type="text/javascript">
                var targetdate = "<?php echo gmdate("m/d/y h:i:s A", strtotime($expirydate)); ?>";
                var startdate = "<?php echo gmdate("m/d/y h:i:s A", strtotime( Mage_Core_Model_Locale::date(null, null ,"en_US",true))); ?>";
                var dealimage = "<?php echo $this->getSkinUrl('images/8.jpg') ?>";
                var buynowreplace = "<?php echo $this->getSkinUrl('images/8.jpg') ?>";
            </script>

            <div class="timerbg_middle clearfix">
                <span class="corner_img"></span>
                <div class="deal_statusnew" >
                    <h4><?php echo $this->__('Time Left To '); ?> <?php echo $this->__('Buy'); ?></h4>   <div class="timerbox" ><div class="viraiterbg">
                            <script type="text/javascript" src="<?php echo $this->getSkinUrl('js/timer.js'); ?>"></script>
                        </div>
                        <div class="timerulbox clearfix">
                            <ul>
                                <li class="clstimerbg"><strong><?php echo $this->__('HOURS'); ?></strong></li>

                                <li class="clstimerbg"><strong><?php echo $this->__('MINUTES'); ?></strong></li>

                                <li class="clstimerbg"><strong><?php echo $this->__('SECONDS'); ?></strong></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--End of Time box-->
    <!--Fine Print and Highlights-->
    <div class="right_column" id="slider-wrapper">
        <div class="banner_middle">
        	<div id="dealSlider" class="nivoSlider">
                <!--<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image'); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" width="440px" height="275px"/>-->
                <img src="<?php echo $this->getSkinUrl('images/sample_deal/01.jpg') ?>" alt="" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>"/>
                <img src="<?php echo $this->getSkinUrl('images/sample_deal/02.jpg') ?>" alt="" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>"/>
                <img src="<?php echo $this->getSkinUrl('images/sample_deal/03.jpg') ?>" alt="" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>"/>
                <img src="<?php echo $this->getSkinUrl('images/sample_deal/04.jpg') ?>" alt="" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>"/>
                <img src="<?php echo $this->getSkinUrl('images/sample_deal/05.jpg') ?>" alt="" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>"/>
            </div>
            
        </div>
        <!--Share Icons-->

            <div class="spread clearfix">
                <span class="floatleft"><?php echo $this->__('Spread it!'); ?></span>
                 <?php
                 // Prepare URL for the facebook dialog feed.
                                $appId = Mage::getStoreConfig('customer/facebook/api_id');
                                $baseUrl = Mage::getBaseUrl();
                                $productImage=$this->helper('catalog/image')->init($_product, 'image');
                                $productName=urlencode($_product->getName());
                                $productDescription=urlencode(strip_tags($_description));
                                $fbUrl = 'http://www.facebook.com/dialog/feed?app_id=' . $appId . '&link=' . $baseUrl . '&description=' . $productDescription . '&picture=' . $productImage . '&name=' . $productName . '&message=&redirect_uri=' . $baseUrl;
                   ?>
                <span class="sharelinks">
                    <a  title="Twitter Share" href="http://twitter.com/home?status=<?php echo $_product->getName(); ?>:<?php echo Mage::getBaseUrl();  ?>" target="_blank"><img src="<?php echo $this->getSkinUrl('images/twitter_smallicon.gif') ?>" width="16" height="16" alt="twitter" title="twitter"/></a>
                    <a  title="Facebook Share" href="<?php  echo $fbUrl; ?>" target="_blank"><img src="<?php echo $this->getSkinUrl('images/facebook_smallicon.gif') ?>" width="16" height="16" alt="facebook" title="facebook"/></a>
                        <?php $baseUrl = Mage::getBaseUrl();
                        $mailBody = $_description.'<br> Url : '.$baseUrl;
                        $mail  = "mailto:?body=".htmlspecialchars(strip_tags($mailBody))."&amp;subject=".$_product->getName();  ?>
                    <a  title="Mail Share" href="<?php echo $mail; ?>" ><img src="<?php echo $this->getSkinUrl('images/mail_smallicon.gif') ?>" width="16" height="16" alt="Mail" title="Mail"/></a>
                </span>
            </div>
        
        <!--End Share Icons-->
        <div class="clsfineprint">
            <h3><?php echo $this->__('The Fine Print'); ?></h3>
            <span><?php echo $fineprint;  ?></span>
        </div>
       <div class="highlights">
            <h3><?php echo $this->__('Highlights'); ?></h3>
                <?php echo $highlight; ?>
        </div>
        <div class="clear"></div>
    </div>
    <!--end of Fine Print and Highlights-->

    <div class="clear"></div>
</div>


<!-- NO Deal available-->
    <?php if($inif !="1") { ?>
<div class="nodealtext clearfix ">  <h1><?php echo $this->__('No Deal Available!'); ?></h1></div>
<fieldset class="no-display">
    <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
    <input type="hidden" name="related_product" id="related-products-field" value="" />
</fieldset>
<div class="clear"></div>
        <?php
    }
    ?>
<!--No Deal Availbale-->
<script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

</div>
<?php endif;
?>
<?php if($inif !="1") {

}else {  ?></div>
<!--end of first content box-->

<div class="clsspace clear"></div>
<div class="reviewbox" style="width:706px;">
        <?php
        if ($_description) :?>
    <div class="bottombox clearfix">
        <div class="bottomleftbox ">
            <div class="description-reviews" >
                <h4  class="clstitle1"><?php echo $this->__('Description') ?></h4>
                <div class="clsdescription"><?php echo $_description; ?></div>

            </div>           
     <div style="padding:10px 10px 10px 20px;">
		 		<fb:comments width="425" ></fb:comments>
				
				<?php $this->addReviewSummaryTemplate('full', 'review/helper/summary_full.phtml')?>
				<?php echo $this->getReviewsSummaryHtml($_product, 'full', true)?>

		 </div>
		 
        </div>
        <div class="bottomrightbox">
            <div class="company-details">
            <div class="com_detail_left" style="display: block; float: left; width: 200px;">
            <h3><?php echo $this->__('The Company'); ?></h3>
                <address><?php  echo $customersite;  ?></address>
                <?php
                $gAddr = explode(',', strip_tags($customersite));
                                    $i = 0;
                                    foreach ($gAddr as $item) {

                                        if ($i != 0) {
                                            $gMapAddr.=', ';
                                        }
                                        $gMapAddr.=trim($item);
                                        $i++;
                                    } 
                ?>
                <?php if(!empty($website)){ ?>
               <p style="margin: 5px 0px;"><a href="http://<?php  echo $website;  ?>" target="_blank"> <?php  echo $website;  ?></a></p>
                <?php } if(!empty($phone)){ ?>
                <p style="margin: 5px 0px;"><?php  echo $phone;  ?></p>
                <?php }?>
            </div>
            <div class="com_detail_right" style="float: right; display: block; width: 450px; padding-left: 10px; border-left: 1px dotted #CCC;">
                        <div id="map_canvas" style="width:450px; height:250px"></div>
            </div>
            <div class="clear" style="clear: both"></div>
            </div></div>
            <?php endif;?>
    <?php } ?>
</div></div>
<!--script to generate google map using customer's address : start-->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
 <script type="text/javascript">
                            var geocoder;
                            var map;

                            geocoder = new google.maps.Geocoder();
                            //var latlng = new google.maps.LatLng(-34.397, 150.644);
                            var myOptions = {
                                zoom: <?php echo $zoom_level?>,
                                //center: latlng,
                                mapTypeId: google.maps.MapTypeId.ROADMAP
                            }

                            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

                            var address = '<?php echo $gMapAddr; ?>';
    geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });


</script>
<!--script to generate google map using customer's address : end-->